package com.kapcb.authentication.context.configuration;

import com.kapcb.authentication.context.core.UserInfoFilter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * <a>Title: UserInfoFilterConfiguration </a>
 * <a>Author: kapcb <a>
 * <a>Description: UserInfoFilterConfiguration <a>
 *
 * @author Kpacb
 * @version 1.0
 * @date 2024/4/27 12:44
 * @since 1.0
 */
@Slf4j
@Configuration
public class UserInfoFilterConfiguration {

    @Bean("userInfoFilter")
    @ConditionalOnMissingBean(value = UserInfoFilter.class)
    public FilterRegistrationBean<UserInfoFilter> userInfoFilter() {
        log.info("begin load UserInfoFilter into IOC ...");
        FilterRegistrationBean<UserInfoFilter> filterRegistrationBean = new FilterRegistrationBean<>();
        filterRegistrationBean.setName("userInfoServletFilter");
        filterRegistrationBean.setOrder(-100);
        filterRegistrationBean.setFilter(new UserInfoFilter());
        filterRegistrationBean.addUrlPatterns("/*");
        return filterRegistrationBean;
    }

}
